﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using uPLibrary.Networking.M2Mqtt;
using uPLibrary.Networking.M2Mqtt.Messages;

namespace WOLPublish
{
    public partial class Form1 : Form
    {
        MqttClient client;

        public Form1()
        {
            InitializeComponent();
        }

        private void btnLight_Click(object sender, EventArgs e)
        {
            string brokerHostName = txtServerIp.Text;
            int brokerPort = 1883;

            try
            {
                client = new MqttClient(brokerHostName, brokerPort, false, null, null, MqttSslProtocols.None);
                //单向SSL通信
                //MqttClient client = new MqttClient(brokerHostName, brokerPort, true, caCert, null, MqttSslProtocols.TLSv1_2, new RemoteCertificateValidationCallback(cafileValidCallback));
                //消息接受
                //连接Broker
                client.Connect("guest");
                Log("连接成功!");
                //client.Connect(clientId, username, password);

                //client.Subscribe(topic, qosLevels);
                client.Publish(txtNode.Text + "/blink", new byte[] { });
                client.Disconnect();
            }
            catch (System.Exception)
            {
                Log("连接失败!");
            }
        }

        private void Log(string v)
        {
            toolStripStatusLabel1.Text = v;
        }
    }
}
